package com.jerry.base.java8.lambda;

import java.util.stream.Stream;

/**
 * this::new的方法引用
 *
 * @author Jerry
 * @since 2024/7/31 15:07
 */
public class MethodRef5 {

    public static void main(String[] args) {
        Util util = new Util();
        util.hiOrder(Stream.of(
                new Student("张无忌", "男"),
                new Student("周芷若", "女"),
                new Student("宋青书", "男")
        ));
    }

    record Student(String name, String sex) {
    }

    static class Util {

        /**
         * 过滤男性学生并打印
         *
         * @param stream
         */
        void hiOrder(Stream<Student> stream) {
            stream
                    .filter(this::isMale)
                    .forEach(System.out::println);
        }

        private boolean isMale(Student stu) {
            return stu.sex().equals("男");
        }
    }

}
